package com.wannengbang.cloudleader.homepage.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wannengbang.cloudleader.R;
import com.wannengbang.cloudleader.bean.ShareListBean;
import com.wannengbang.cloudleader.homepage.ShareBonusDetailsActivity;
import com.wannengbang.cloudleader.utils.NumberFormatUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Author: HWC
 */
public class ShareBonusListAdapter extends RecyclerView.Adapter<ShareBonusListAdapter.ViewHolder> {

    private List<ShareListBean.DataBean.ItemListBean> listsBeans;
    private Context context;

    public ShareBonusListAdapter(List<ShareListBean.DataBean.ItemListBean> listsBeans) {
        this.listsBeans = listsBeans;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
        context = viewGroup.getContext();
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_share_bonus_list, viewGroup, false);
        ViewHolder viewHolder = new ViewHolder(inflate);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        ShareListBean.DataBean.ItemListBean dataBean = listsBeans.get(position);
        holder.tvDate.setText("日期：" + dataBean.getMonth() + "");
        String money = NumberFormatUtils.formatTwoDecimal(Double.parseDouble(dataBean.getMoney_sum()) / 100);
        holder.tvMoney.setText("总金额：" + money + "元");
        holder.tvAgentCount.setText("董事人数：" + dataBean.getAgent_count());
        holder.tvStartCount.setText("星级数量：" + dataBean.getStar_sum());
        holder.itemView.setOnClickListener(v -> {
            Intent intent = new Intent(context, ShareBonusDetailsActivity.class);
            intent.putExtra("id", dataBean.getId() + "");
            intent.putExtra("money", money);
            intent.putExtra("date", dataBean.getMonth() + "");
            context.startActivity(intent);
        });
    }

    @Override
    public int getItemCount() {
        return listsBeans.size() == 0 ? 0 : listsBeans.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_date)
        TextView tvDate;
        @BindView(R.id.tv_money)
        TextView tvMoney;
        @BindView(R.id.tv_agent_count)
        TextView tvAgentCount;
        @BindView(R.id.tv_start_count)
        TextView tvStartCount;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
